package com.chance.cc.crawler.development.bootstrap.xiaohongshu;

import com.alibaba.fastjson.JSON;
import com.chance.cc.crawler.core.downloader.HttpConfig;
import com.chance.cc.crawler.core.downloader.HttpPage;
import com.chance.cc.crawler.core.downloader.HttpRequest;
import com.chance.cc.crawler.core.downloader.HttpRequestBody;
import com.chance.cc.crawler.core.downloader.http.HttpClientDownloader;
import com.chance.cc.crawler.core.downloader.http.HttpClientGenerator;
import com.chance.cc.crawler.core.downloader.proxy.Proxy;
import com.chance.cc.crawler.core.downloader.proxy.SiteConfigProxyProvider;
import com.chance.cc.crawler.core.selector.Json;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.RandomStringUtils;

import java.io.FileInputStream;
import java.io.IOException;
import java.math.BigInteger;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author bx
 * @date 2021/8/30 0030 10:13
 */
public class XHSAppApiTest {
    private static Proxy proxy = new Proxy();

    static {
        //代理配置
        proxy.setHost("http-dyn.abuyun.com");
        proxy.setPort(9020);
        proxy.setUsername("HL89Q19E86E2987D");
        proxy.setPassword("71F33D94CE5F7BF2");
    }

    public static void main(String[] args) {
        HttpConfig httpConfig = HttpConfig.me("test");
        httpConfig.setProxy(proxy);
        httpConfig.setUseProxy(false);

        HttpClientDownloader downloader = new HttpClientDownloader();
        downloader.setClientGenerator(new HttpClientGenerator());
        downloader.setProxyProvider(new SiteConfigProxyProvider());

        for (int i = 1; i <= 1; i++) {
            new Thread(new TestSearchNotesRun(downloader, httpConfig), "thread_" + i).start();
        }
    }

    static class TestArticleRun implements Runnable {

        HttpClientDownloader downloader;
        HttpConfig httpConfig;

        public TestArticleRun(HttpClientDownloader downloader, HttpConfig httpConfig) {
            this.downloader = downloader;
            this.httpConfig = httpConfig;
        }

        @Override
        public void run() {
            String url = "https://edith.xiaohongshu.com/api/sns/v1/note/feed?note_id=616fd8c70000000001028e70&page=1&num=5&fetch_mode=1&source=explore&ads_track_id=";

//            Map<String,String> XHSRequest = new HashMap<>();
//            XHSRequest.put("x_b3_traceId", RandomStringUtils.random(16,"0123456789abcdef"));
//            XHSRequest.put("xy_common_params", "fid=163031008510ed2798ab571f9a126d5755868bd9d89e&device_fingerprint=202108301555173e46cf0e71b9ee442c0277b8fc88ae550167824f9f6ea72d&device_fingerprint1=202108301555173e46cf0e71b9ee442c0277b8fc88ae550167824f9f6ea72d&launch_id=1630311468&tz=Asia%2FShanghai&channel=PMgdt17777612&versionName=6.73.0.1&deviceId=37a47c97-5542-3917-93c7-dbf465a770a3&platform=android&sid=session.1630311510161100281080&identifier_flag=6&t=1630311550&project_id=ECFAAF&build=6730157&x_trace_page_current=explore_feed&lang=zh-Hans&app_id=ECFAAF01&uis=light");
//            XHSRequest.put("userAgent", "Dalvik/2.1.0 (Linux; U; Android 8.0.0; MI 5s MIUI/9.8.29) Resolution/1080*1920 Version/6.73.0.1 Build/6730157 Device/(Xiaomi;MI 5s) discover/6.73.0.1 NetType/WiFi");
//            XHSRequest.put("mainHmac", "J8NdoGPX8rCpPdP17HEJrpheH1wCXvAqzR1CczNfSwKwg0eVCT/heWoGn35/mArtw5H37rywvV+RvbLLpghIXgsC6fyrKdYlMLefY1ByaJix/4ktM1FmJr1H0JJGUZkW");
//            XHSRequest.put("deviceId", "37a47c97-5542-3917-93c7-dbf465a770a3");
//            XHSRequest.put("url", url);
            String XHSRequestStr = "{\"dvmKey\":\"ce5de1dc-2ab4-3c72-9c05-871991a1fee1\",\"requestTracePage\":\"user_follow_page\"," +
                    "\"requestUrl\":\""+url+"\"}";

            HttpRequest xhsShieldRequest = new HttpRequest();
            xhsShieldRequest.setUrl("http://192.168.1.227:9983/xhs/decode/shield");
            xhsShieldRequest.setMethod("POST");
            xhsShieldRequest.setRequestBody(HttpRequestBody.json(XHSRequestStr,"utf-8"));
            HttpPage xhsShieldPage = downloader.download(xhsShieldRequest, HttpConfig.me("xhs_shield"));
            String xhsShieldHeaders = xhsShieldPage.getRawText();
            System.out.println(xhsShieldHeaders);

            Map map = JSON.parseObject(new Json(xhsShieldPage.getRawText()).jsonPath("content.requestHeaders").get(), Map.class);

            HttpRequest httpRequest = new HttpRequest();
            httpRequest.setUrl(url);
            httpRequest.setHeaders(map);
            httpRequest.addHeader("Host","edith.xiaohongshu.com");
            httpRequest.addHeader("Connection","Keep-Alive");
            httpRequest.addHeader("Accept-Encoding","gzip");
//            httpRequest.addHeader("X-B3-TraceId",((List)map.get("x-b3-traceid")).get(0).toString());
//            httpRequest.addHeader("xy-common-params", ((List)map.get("xy-common-params")).get(0).toString());
//            httpRequest.addHeader("User-Agent", ((List)map.get("user-agent")).get(0).toString());
//            httpRequest.addHeader("shield", ((List)map.get("shield")).get(0).toString());
//            httpRequest.addHeader("xy-platform-info", ((List)map.get("xy-platform-info")).get(0).toString());
            HttpPage download = downloader.download(httpRequest, httpConfig);


            System.out.println(download.getRawText());
        }
    }

    private static List<String> getAddSearchKWs() throws IOException {
        List<String> kws = IOUtils.readLines(new FileInputStream("E:\\data\\xhs\\search_kw.txt"), "utf-8");

        List<String> keywordsBeans = new ArrayList<>();
        for (String kw : kws) {
            keywordsBeans.add(kw);
        }
        return keywordsBeans;
    }

    static class TestBDArticleRun implements Runnable {

        HttpClientDownloader downloader;
        HttpConfig httpConfig;

        public TestBDArticleRun(HttpClientDownloader downloader, HttpConfig httpConfig) {
            this.downloader = downloader;
            this.httpConfig = httpConfig;
        }

        @Override
        public void run() {
            while (true){
                String url = "https://www.xiaohongshu.com/fe_api/burdock/baidu/v2/note/617d5ede000000002103cf44";
                HttpRequest httpRequest = new HttpRequest();
                httpRequest.setUrl(url);
                httpRequest.addHeader("Host","www.xiaohongshu.com");
                httpRequest.addHeader("asid","20211101e2c57e9866213ff5bee8319f");
                httpRequest.addHeader("X-Sign","Xa9a43f6ee51b223d58f695fa9faa9092");

                HttpPage download = downloader.download(httpRequest, httpConfig);


                System.out.println(download.getRawText());
            }
        }
    }

    static class TestSearchNotesRun implements Runnable {

        HttpClientDownloader downloader;
        HttpConfig httpConfig;

        public TestSearchNotesRun(HttpClientDownloader downloader, HttpConfig httpConfig) {
            this.downloader = downloader;
            this.httpConfig = httpConfig;
        }

        @Override
        public void run() {
            List<String> searchKWs  =null;
            try {
                 searchKWs = getAddSearchKWs();

                for (String searchKW : searchKWs) {
                    String url = "https://edith.xiaohongshu.com/api/sns/v10/search/notes?keyword="+ URLEncoder.encode(searchKW,"utf-8") +"&filters=%5B%5D" +
                            "&sort=time_descending&page=1&page_size=20&source=explore_feed&search_id=28zp5evbcbsbdjzydh0xs%4028zp5fnc6k2ogkwl97vgg" +
                            "&api_extra=&page_pos=0&pin_note_id=&allow_rewrite=1&word_request_id=&clicked_card=";

                    String XHSRequestStr = "{\"dvmKey\":\"01b872b2-7e5d-3b9f-95b3-3ead772f8502\",\"requestTracePage\":\"search_result_users\"," +
                            "\"requestUrl\":\""+url+"\"}";

                    HttpRequest xhsShieldRequest = new HttpRequest();
                    xhsShieldRequest.setUrl("http://localhost:9983/xhs/decode/shield");
                    xhsShieldRequest.setMethod("POST");
                    xhsShieldRequest.setRequestBody(HttpRequestBody.json(XHSRequestStr,"UTF-8"));
                    HttpPage xhsShieldPage = downloader.download(xhsShieldRequest, HttpConfig.me("xhs_shield"));
                    String xhsShieldHeaders = xhsShieldPage.getRawText();
                    System.out.println(xhsShieldHeaders);

                    Map map = JSON.parseObject(new Json(xhsShieldPage.getRawText()).jsonPath("content.requestHeaders").get(), Map.class);

                    HttpRequest httpRequest = new HttpRequest();
                    httpRequest.setUrl(url);
                    httpRequest.setHeaders(map);
                    httpRequest.addHeader("Host","edith.xiaohongshu.com");
                    httpRequest.addHeader("Connection","Keep-Alive");
                    httpRequest.addHeader("Accept-Encoding","gzip");
//            httpRequest.addHeader("X-B3-TraceId",((List)map.get("x-b3-traceid")).get(0).toString());
//            httpRequest.addHeader("xy-common-params", ((List)map.get("xy-common-params")).get(0).toString());
//            httpRequest.addHeader("User-Agent", ((List)map.get("user-agent")).get(0).toString());
//            httpRequest.addHeader("shield", ((List)map.get("shield")).get(0).toString());
//            httpRequest.addHeader("xy-platform-info", ((List)map.get("xy-platform-info")).get(0).toString());
                    HttpPage download = downloader.download(httpRequest, httpConfig);


                    System.out.println(download.getRawText());
                }

            } catch (Exception e) {
                e.printStackTrace();
            }


        }
    }

    static class TestSearchUsersRun implements Runnable {

        HttpClientDownloader downloader;
        HttpConfig httpConfig;

        public TestSearchUsersRun(HttpClientDownloader downloader, HttpConfig httpConfig) {
            this.downloader = downloader;
            this.httpConfig = httpConfig;
        }

        @Override
        public void run() {
            String url = "https://www.xiaohongshu.com/api/sns/v3/search/user?keyword=%E8%80%90%E5%85%8B&page=1&page_size=20&search_id="+searchId();

            String XHSRequestStr = "{\"dvmKey\":\"ce5de1dc-2ab4-3c72-9c05-871991a1fee1\",\"requestTracePage\":\"search_result_users\"," +
                    "\"requestUrl\":\""+url+"\"}";

            HttpRequest xhsShieldRequest = new HttpRequest();
            xhsShieldRequest.setUrl("http://localhost:9981/xhs/decode/shield");
            xhsShieldRequest.setMethod("POST");
            xhsShieldRequest.setRequestBody(HttpRequestBody.json(XHSRequestStr,"UTF-8"));
            HttpPage xhsShieldPage = downloader.download(xhsShieldRequest, HttpConfig.me("xhs_shield"));
            String xhsShieldHeaders = xhsShieldPage.getRawText();
            System.out.println(xhsShieldHeaders);

            Map map = JSON.parseObject(new Json(xhsShieldPage.getRawText()).jsonPath("content.requestHeaders").get(), Map.class);

            HttpRequest httpRequest = new HttpRequest();
            httpRequest.setUrl(url);
            httpRequest.setHeaders(map);
            httpRequest.addHeader("Host","www.xiaohongshu.com");
            httpRequest.addHeader("Connection","Keep-Alive");
            httpRequest.addHeader("Accept-Encoding","gzip");
            HttpPage download = downloader.download(httpRequest, httpConfig);

            System.out.println(download.getRawText());
        }
    }

    private static String searchId(){
        byte[] bArr = new byte[16];
        long currentTimeMillis = System.currentTimeMillis() & Long.MAX_VALUE;
        long random = ((long) (Math.random() * ((double) Long.MAX_VALUE))) & Long.MAX_VALUE;
        for (int i = 0; i <= 7; i++) {
            int i2 = 56 - (i << 3);
            bArr[i] = (byte) ((int) (currentTimeMillis >>> i2));
            bArr[i + 8] = (byte) ((int) (random >>> i2));
        }
        String bigInteger = new BigInteger(bArr).toString(36);
        return bigInteger;
    }

    static class TestCommentRun implements Runnable {

        HttpClientDownloader downloader;
        HttpConfig httpConfig;

        public TestCommentRun(HttpClientDownloader downloader, HttpConfig httpConfig) {
            this.downloader = downloader;
            this.httpConfig = httpConfig;
        }

        @Override
        public void run() {
            String url = "https://edith.xiaohongshu.com/api/sns/v5/note/comment/list?note_id=610a8dc0000000002103bd32&" +
                    "start=612a5f67000000002103c6df&num=15&show_priority_sub_comments=0&source=explore&top_comment_id=";

            Map<String,String> XHSRequest = new HashMap<>();
            XHSRequest.put("x_b3_traceId", RandomStringUtils.random(16,"0123456789abcdef"));
            XHSRequest.put("xy_common_params", "fid=163031008510ed2798ab571f9a126d5755868bd9d89e&device_fingerprint=202108301555173e46cf0e71b9ee442c0277b8fc88ae550167824f9f6ea72d&device_fingerprint1=202108301555173e46cf0e71b9ee442c0277b8fc88ae550167824f9f6ea72d&launch_id=1630311468&tz=Asia%2FShanghai&channel=PMgdt17777612&versionName=6.73.0.1&deviceId=37a47c97-5542-3917-93c7-dbf465a770a3&platform=android&sid=session.1630311510161100281080&identifier_flag=6&t=1630311550&project_id=ECFAAF&build=6730157&x_trace_page_current=explore_feed&lang=zh-Hans&app_id=ECFAAF01&uis=light");
            XHSRequest.put("userAgent", "Dalvik/2.1.0 (Linux; U; Android 8.0.0; MI 5s MIUI/9.8.29) Resolution/1080*1920 Version/6.73.0.1 Build/6730157 Device/(Xiaomi;MI 5s) discover/6.73.0.1 NetType/WiFi");
            XHSRequest.put("mainHmac", "J8NdoGPX8rCpPdP17HEJrpheH1wCXvAqzR1CczNfSwKwg0eVCT/heWoGn35/mArtw5H37rywvV+RvbLLpghIXgsC6fyrKdYlMLefY1ByaJix/4ktM1FmJr1H0JJGUZkW");
            XHSRequest.put("deviceId", "37a47c97-5542-3917-93c7-dbf465a770a3");
            XHSRequest.put("url", url);

            HttpRequest xhsShieldRequest = new HttpRequest();
            xhsShieldRequest.setUrl("http://localhost:8080/crawler/unidbg/api/v1/xhs/shield");
            xhsShieldRequest.setMethod("POST");
            xhsShieldRequest.setRequestBody(HttpRequestBody.json(JSON.toJSONString(XHSRequest),"UTF-8"));
            HttpPage xhsShieldPage = downloader.download(xhsShieldRequest, HttpConfig.me("xhs_shield"));
            String xhsShieldHeaders = xhsShieldPage.getRawText();
            System.out.println(xhsShieldHeaders);

            Map map = JSON.parseObject(xhsShieldHeaders, Map.class);

            HttpRequest httpRequest = new HttpRequest();
            httpRequest.setUrl(url);
            httpRequest.setHeaders(map);
            httpRequest.addHeader("Host","edith.xiaohongshu.com");
            httpRequest.addHeader("Connection","Keep-Alive");
            httpRequest.addHeader("Accept-Encoding","gzip");
//            httpRequest.addHeader("X-B3-TraceId",((List)map.get("x-b3-traceid")).get(0).toString());
//            httpRequest.addHeader("xy-common-params", ((List)map.get("xy-common-params")).get(0).toString());
//            httpRequest.addHeader("User-Agent", ((List)map.get("user-agent")).get(0).toString());
//            httpRequest.addHeader("shield", ((List)map.get("shield")).get(0).toString());
//            httpRequest.addHeader("xy-platform-info", ((List)map.get("xy-platform-info")).get(0).toString());
            HttpPage download = downloader.download(httpRequest, httpConfig);


            System.out.println(download.getRawText());
        }
    }

    static class TestSubCommentRun implements Runnable {

        HttpClientDownloader downloader;
        HttpConfig httpConfig;

        public TestSubCommentRun(HttpClientDownloader downloader, HttpConfig httpConfig) {
            this.downloader = downloader;
            this.httpConfig = httpConfig;
        }

        @Override
        public void run() {
            String url = "https://edith.xiaohongshu.com/api/sns/v2/note/comment/sub_comments?" +
                    "note_id=613ea6fd000000000102819f&comment_id=613ebbd9000000002103f872&" +
                    "start=613ebd46000000000102403e&num=5&source=&filter_sub_comment_id=";

            String XHSRequestStr = "{\"dvmKey\":\"ce5de1dc-2ab4-3c72-9c05-871991a1fee1\",\"requestTracePage\":\"note_comment_page\"," +
                    "\"requestUrl\":\""+url+"\"}";

            HttpRequest xhsShieldRequest = new HttpRequest();
            xhsShieldRequest.setUrl("http://localhost:9981/xhs/decode/shield");
            xhsShieldRequest.setMethod("POST");
            xhsShieldRequest.setRequestBody(HttpRequestBody.json(XHSRequestStr,"UTF-8"));
            HttpPage xhsShieldPage = downloader.download(xhsShieldRequest, HttpConfig.me("xhs_shield"));
            String xhsShieldHeaders = xhsShieldPage.getRawText();
            System.out.println(xhsShieldHeaders);

            Map map = JSON.parseObject(new Json(xhsShieldPage.getRawText()).jsonPath("content.requestHeaders").get(), Map.class);

            HttpRequest httpRequest = new HttpRequest();
            httpRequest.setUrl(url);
            httpRequest.setHeaders(map);
            httpRequest.addHeader("Host","edith.xiaohongshu.com");
            httpRequest.addHeader("Connection","Keep-Alive");
            httpRequest.addHeader("Accept-Encoding","gzip");
            HttpPage download = downloader.download(httpRequest, httpConfig);


            System.out.println(download.getRawText());
        }
    }

    static class TestHomeDiscoveryRun implements Runnable {

        HttpClientDownloader downloader;
        HttpConfig httpConfig;

        public TestHomeDiscoveryRun(HttpClientDownloader downloader, HttpConfig httpConfig) {
            this.downloader = downloader;
            this.httpConfig = httpConfig;
        }

        @Override
        public void run() {
            String url = "https://edith.xiaohongshu.com/api/sns/v6/homefeed?oid=homefeed.funny_v3&cursor_score=" +
                    "&geo=eyJsYXRpdHVkZSI6MC4wMDAwMDAsImxvbmdpdHVkZSI6MC4wMDAwMDB9%0A&trace_id=e27314a5-bc1a-3046-9607-a02df92189f5" +
                    "&note_index=0&refresh_type=0&client_volume=0.00&preview_ad=" +
                    "&loaded_ad=%7B%22ads_id_list%22%3A%5B%5D%7D&personalization=1" +
                    "&pin_note_id=&pin_note_source=&unread_begin_note_id=&unread_end_note_id=&unread_note_count=0";

            String XHSRequestStr = "{\"dvmKey\":\"ce5de1dc-2ab4-3c72-9c05-871991a1fee1\",\"requestTracePage\":\"app_loading_page\"," +
                    "\"requestUrl\":\""+url+"\"}";

            HttpRequest xhsShieldRequest = new HttpRequest();
            xhsShieldRequest.setUrl("http://localhost:9981/xhs/decode/shield");
            xhsShieldRequest.setMethod("POST");
            xhsShieldRequest.setRequestBody(HttpRequestBody.json(XHSRequestStr,"UTF-8"));
            HttpPage xhsShieldPage = downloader.download(xhsShieldRequest, HttpConfig.me("xhs_shield"));
            String xhsShieldHeaders = xhsShieldPage.getRawText();
            System.out.println(xhsShieldHeaders);

            Map map = JSON.parseObject(new Json(xhsShieldPage.getRawText()).jsonPath("content.requestHeaders").get(), Map.class);

            HttpRequest httpRequest = new HttpRequest();
            httpRequest.setUrl(url);
            httpRequest.setHeaders(map);
            httpRequest.addHeader("Host","edith.xiaohongshu.com");
            httpRequest.addHeader("Connection","Keep-Alive");
            httpRequest.addHeader("Accept-Encoding","gzip");
            HttpPage download = downloader.download(httpRequest, httpConfig);


            System.out.println(download.getRawText());
        }
    }

    /**
     * 用户关注接口
     */
    static class TestUserFollowingsRun implements Runnable {

        HttpClientDownloader downloader;
        HttpConfig httpConfig;

        public TestUserFollowingsRun(HttpClientDownloader downloader, HttpConfig httpConfig) {
            this.downloader = downloader;
            this.httpConfig = httpConfig;
        }

        @Override
        public void run() {
            String url = "https://www.xiaohongshu.com/api/sns/v2/user/5a152ef8e8ac2b5c7a805197/followings?start=&source=my_following";

            String XHSRequestStr = "{\"dvmKey\":\"ce5de1dc-2ab4-3c72-9c05-871991a1fee1\",\"requestTracePage\":\"user_follow_page\"," +
                    "\"requestUrl\":\""+url+"\"}";

            HttpRequest xhsShieldRequest = new HttpRequest();
            xhsShieldRequest.setUrl("http://localhost:9981/xhs/decode/shield");
            xhsShieldRequest.setMethod("POST");
            xhsShieldRequest.setRequestBody(HttpRequestBody.json(XHSRequestStr,"UTF-8"));
            HttpPage xhsShieldPage = downloader.download(xhsShieldRequest, HttpConfig.me("xhs_shield"));
            String xhsShieldHeaders = xhsShieldPage.getRawText();
            System.out.println(xhsShieldHeaders);

            Map map = JSON.parseObject(new Json(xhsShieldPage.getRawText()).jsonPath("content.requestHeaders").get(), Map.class);

            HttpRequest httpRequest = new HttpRequest();
            httpRequest.setUrl(url);
            httpRequest.setHeaders(map);
            httpRequest.addHeader("Host","www.xiaohongshu.com");
            httpRequest.addHeader("Connection","Keep-Alive");
            httpRequest.addHeader("Accept-Encoding","gzip");
            HttpPage download = downloader.download(httpRequest, httpConfig);


            System.out.println(download.getRawText());
        }
    }

    /**
     * 用户明细接口
     */
    static class TestUserDetailInfoRun implements Runnable {

        HttpClientDownloader downloader;
        HttpConfig httpConfig;

        public TestUserDetailInfoRun(HttpClientDownloader downloader, HttpConfig httpConfig) {
            this.downloader = downloader;
            this.httpConfig = httpConfig;
        }

        @Override
        public void run() {
            String url = "https://edith.xiaohongshu.com/api/sns/v3/user/info?user_id=5d52aece00000000160214ce";

            String XHSRequestStr = "{\"dvmKey\":\"ce5de1dc-2ab4-3c72-9c05-871991a1fee1\",\"requestTracePage\":\"user_follow_page\"," +
                    "\"requestUrl\":\""+url+"\"}";

            HttpRequest xhsShieldRequest = new HttpRequest();
            xhsShieldRequest.setUrl("http://localhost:9981/xhs/decode/shield");
            xhsShieldRequest.setMethod("POST");
            xhsShieldRequest.setRequestBody(HttpRequestBody.json(XHSRequestStr,"UTF-8"));
            HttpPage xhsShieldPage = downloader.download(xhsShieldRequest, HttpConfig.me("xhs_shield"));
            String xhsShieldHeaders = xhsShieldPage.getRawText();
            System.out.println(xhsShieldHeaders);

            Map map = JSON.parseObject(new Json(xhsShieldPage.getRawText()).jsonPath("content.requestHeaders").get(), Map.class);

            HttpRequest httpRequest = new HttpRequest();
            httpRequest.setUrl(url);
            httpRequest.setHeaders(map);
            httpRequest.addHeader("Host","edith.xiaohongshu.com");
            httpRequest.addHeader("Connection","Keep-Alive");
            httpRequest.addHeader("Accept-Encoding","gzip");
            HttpPage download = downloader.download(httpRequest, httpConfig);

            System.out.println(download.getRawText());
        }
    }

    /**
     * 用户发文列表接口
     */
    static class TestUserNoteListRun implements Runnable {

        HttpClientDownloader downloader;
        HttpConfig httpConfig;

        public TestUserNoteListRun(HttpClientDownloader downloader, HttpConfig httpConfig) {
            this.downloader = downloader;
            this.httpConfig = httpConfig;
        }

        @Override
        public void run() {
            String url = "https://edith.xiaohongshu.com/api/sns/v4/note/user/posted?user_id=5cbe8341000000001702a096" +
                    "&sub_tag_id=&cursor=&num=10&use_cursor=true&pin_note_id=&pin_note_ids=";

            String XHSRequestStr = "{\"dvmKey\":\"ce5de1dc-2ab4-3c72-9c05-871991a1fee1\",\"requestTracePage\":\"user_follow_page\"," +
                    "\"requestUrl\":\""+url+"\"}";

            HttpRequest xhsShieldRequest = new HttpRequest();
            xhsShieldRequest.setUrl("http://192.168.1.227:9983/xhs/decode/shield");
            xhsShieldRequest.setMethod("POST");
            xhsShieldRequest.setRequestBody(HttpRequestBody.json(XHSRequestStr,"UTF-8"));
            HttpPage xhsShieldPage = downloader.download(xhsShieldRequest, HttpConfig.me("xhs_shield"));
            String xhsShieldHeaders = xhsShieldPage.getRawText();
            System.out.println(xhsShieldHeaders);

            Map map = JSON.parseObject(new Json(xhsShieldPage.getRawText()).jsonPath("content.requestHeaders").get(), Map.class);

            HttpRequest httpRequest = new HttpRequest();
            httpRequest.setUrl(url);
            httpRequest.setHeaders(map);
            httpRequest.addHeader("Host","edith.xiaohongshu.com");
            httpRequest.addHeader("Connection","Keep-Alive");
            httpRequest.addHeader("Accept-Encoding","gzip");
            HttpPage download = downloader.download(httpRequest, httpConfig);

            System.out.println(download.getRawText());
        }
    }
}


